/**
 * 
 */
package javapop.framework.generic;

import java.util.ArrayList;
import java.util.List;

import javapop.framework.generic.tool.GrammarVisitor;

/**
 * @author hakim
 *
 */
public class GChoice implements GParser {
	
	private List<GParser> choices;

	/**
	 * @param content 
	 * 
	 */
	public GChoice(List<GParser> content) {
		this.choices = new ArrayList<GParser>(content);
	}

	public List<GParser> getChoices() {
		return choices;
	}

	@Override
	public <T,R,E extends Exception> T visit(GrammarVisitor<T,R, E> g) throws E {
		return g.visit(this);
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("Choice(");
		for(int i = 0; i < choices.size(); i++) {
			sb.append(choices.get(i).toString());
			if(i == choices.size() - 1)
				sb.append(")");
			else
				sb.append(",");
		}
		return sb.toString();
	}
}
